﻿#include "pch.h"

#ifdef _MSC_VER
HMODULE hmodule = NULL;
#else
void *hmodule = NULL;
#endif

char outBuf[1024];
char uniformFormat[1024];
int32_t toggleVer = true;

void OutputDebugString1(const char *str)
{
#ifdef ___MSC_VER
    FILE *fp = NULL;
    fopen_s(&fp, "./out.txt", "a+t");
#else
    FILE *fp = fopen("./out.txt", "a+t");
#endif
    fputs(str, fp);
    fclose(fp);
}

#ifndef _MSC_VER
void OutputDebugString(const char *str)
{
    printf("%s", str);
}
#endif

void println(const char *format, ...)
{
#ifndef _DEBUG
    return;
#endif
    return;
    va_list pArgs;
    va_start(pArgs, format);
    strncpy(uniformFormat, "\n", sizeof(uniformFormat));
    uniformFormat[sizeof(uniformFormat) - 1] = 0;
    strncat(uniformFormat, format, sizeof(uniformFormat) - strlen(uniformFormat));
    uniformFormat[sizeof(uniformFormat) - 1] = 0;
    strncat(uniformFormat, "\n", sizeof(uniformFormat) - strlen(uniformFormat));
    uniformFormat[sizeof(uniformFormat) - 1] = 0;
    vsprintf(outBuf, uniformFormat, pArgs);
    // OutputDebugStringA( outBuf );
    va_end(pArgs);
}

void printxln(const char *format, ...)
{
#ifndef _DEBUG
    return;
#endif
    return;
    va_list pArgs;
    va_start(pArgs, format);
    strncpy(uniformFormat, "", sizeof(uniformFormat));
    uniformFormat[sizeof(uniformFormat) - 1] = 0;
    strncat(uniformFormat, format, sizeof(uniformFormat) - strlen(uniformFormat));
    uniformFormat[sizeof(uniformFormat) - 1] = 0;
    strncat(uniformFormat, "\n", sizeof(uniformFormat) - strlen(uniformFormat));
    uniformFormat[sizeof(uniformFormat) - 1] = 0;
    vsprintf(outBuf, uniformFormat, pArgs);
    // OutputDebugStringA( outBuf );
    va_end(pArgs);
}

#define MAX_LEN 40960
void print4x(void *pVoid, int32_t size, const char *caption)
{
#ifndef _DEBUG
    return;
#endif
    return;
    int32_t rowNum = 8;
    unsigned *pInt = (unsigned *)((int64_t)pVoid / (int64_t)(4 * rowNum) * (4 * rowNum));

    if (size < 0)
    {
        size = 0;
    }
    if (size > MAX_LEN)
    {
        size = MAX_LEN;
    }
    size = (int32_t)(size + ((int64_t)pVoid - (int64_t)pInt)) / 4;
    println("%s(%d lines):%08X ==>\n", caption, (size + rowNum - 1) / rowNum, pVoid);
    for (int32_t i = 0; i < (size + rowNum - 1) / rowNum; i++)
    {
        char *buf = new char[MAX_LEN];
        char num[16];
        strncpy(buf, "", MAX_LEN);
        memset(num, 0, 16);
        for (int32_t j = 0; j < rowNum; j++)
        {
            if (i * rowNum + j < size && (int64_t)((i * rowNum + j) * 4) + (int64_t)pInt >= (int64_t)pVoid)
            {
                memset(num, 0, 16);
                sprintf(num, "%08X", pInt[i * rowNum + j]);
                buf[MAX_LEN - 1] = 0;
                strncat(buf, num, MAX_LEN - strlen(buf));
                buf[MAX_LEN - 1] = 0;
                strncat(buf, " ", MAX_LEN - strlen(buf));
                buf[MAX_LEN - 1] = 0;
            }
            else
            {
                memset(num, 0, 16);
                sprintf(num, "........");
                buf[MAX_LEN - 1] = 0;
                strncat(buf, num, MAX_LEN - strlen(buf));
                buf[MAX_LEN - 1] = 0;
                strncat(buf, " ", MAX_LEN - strlen(buf));
                buf[MAX_LEN - 1] = 0;
            }
        }
        buf[MAX_LEN - 1] = 0;
        if (strlen(buf) > 0)
        {
            printxln(buf);
        }
        delete[] buf;
    }
}

void printTSMPBAG(TSMPBAG *p)
{
    return;
    if (p)
    {
        println("TSMPBAG:{metric=%p,rawbag=%p,Base=%p,baseMaxTime=%d}", p->metric, p->rawbag, p->Base,
                p->baseMaxTime);
        if (p->metric)
        {
            TDLLMETRIC *pTDLLMETRIC = (TDLLMETRIC *)p->metric;
            println("TSMPBAG.metric:{\n\t enrich=%lf, \n\t amount=%lf, \n\t dilution=%lf, \n\t injVolume=%lf, \n\t "
                    "byCalib=%s, \n\t concFactor=%d, \n\t amtK=%d, \n\t istdK=%d, \n\t columnLength=%f, \n\t "
                    "deadTime=%f\n}",
                    pTDLLMETRIC->enrich, pTDLLMETRIC->amount, pTDLLMETRIC->dilution, pTDLLMETRIC->injVolume,
                    pTDLLMETRIC->byCalib ? "true" : "false", pTDLLMETRIC->concFactor, pTDLLMETRIC->amtK,
                    pTDLLMETRIC->istdK, pTDLLMETRIC->columnLength, pTDLLMETRIC->deadTime);
        }
        if (p->rawbag)
        {
            TRAWBAG *pTRAWBAG = (TRAWBAG *)p->rawbag;
            println("TSMPBAG.rawbag:{head=%p,len=%d,time=%p,*time=%d,freq=%p,*freq=%d}", pTRAWBAG->head, pTRAWBAG->len,
                    pTRAWBAG->time, pTRAWBAG->time ? *pTRAWBAG->time : 0, pTRAWBAG->freq,
                    pTRAWBAG->freq ? *pTRAWBAG->freq : 0);
            if (pTRAWBAG->time && *pTRAWBAG->time > 0)
            {
                print4x(pTRAWBAG->head, std::max(*pTRAWBAG->time * (int32_t)sizeof(int32_t), pTRAWBAG->len),
                        "TSMPBAG.rawbag.head");
            }
        }
        if (p->Base)
        {
            print4x(p->Base, p->baseMaxTime * 4, "TSMPBAG.Base");
        }
    }
}
void printTDLLIPINF(TDLLIPINF *p)
{
    return;
    if (p)
    {
        println("IPINF:{ipara=%p,tprgInf=%p}", p->ipara, p->tprgInf);
        if (p->ipara)
        {
            TIPara *pTIPara = (TIPara *)p->ipara;
            println("IPINF.ipara:{\n\t pkWidth=%f, \n\t pkNoise=%ld, \n\t pkDrift=%f, \n\t testPkWidth=%f, \n\t "
                    "testPkNoise=%ld, \n\t testPkDrift=%f, \n\t initTime=%f, \n\t stopTime=%f, \n\t minArea=%ld, \n\t "
                    "minHeight=%ld, \n\t wdMode=%d, \n\t tdouble=%f, \n\t tailMode=%d, \n\t autoNegative=%s, \n\t "
                    "shouldSens=%s, \n\t tprgUsed=%s, \n\t width=%d, \n\t slope=%f, \n\t drift=%f, \n\t no=%s\n}",
                    pTIPara->pkWidth, pTIPara->pkNoise, pTIPara->pkDrift, pTIPara->testPkWidth, pTIPara->testPkNoise,
                    pTIPara->testPkDrift, pTIPara->initTime, pTIPara->stopTime, pTIPara->minArea, pTIPara->minHeight,
                    pTIPara->wdMode, pTIPara->tdouble, pTIPara->tailMode, pTIPara->autoNegative ? "true" : "false",
                    pTIPara->shouldSens ? "true" : "false", pTIPara->tprgUsed ? "true" : "false", pTIPara->width,
                    pTIPara->slope, pTIPara->drift, pTIPara->nop);
        }
        if (p->tprgInf)
        {
            TDLLTPRGINF *pTDLLTPRGINF = (TDLLTPRGINF *)p->tprgInf;
            println("IPINF.tprgInf:{head=%p,len=%d,num=%p,*num=%d}", pTDLLTPRGINF->head, pTDLLTPRGINF->len,
                    pTDLLTPRGINF->num, pTDLLTPRGINF->num ? *pTDLLTPRGINF->num : 0);
            if (pTDLLTPRGINF->num && *pTDLLTPRGINF->num > 0)
            {
                print4x(pTDLLTPRGINF->head,
                        std::max(*pTDLLTPRGINF->num * (int32_t)sizeof(TDLLTPRGListItem), pTDLLTPRGINF->len),
                        "IPINF.tprgInf.head");
            }
        }
    }
}
void printTDLLEPINF(TDLLEPINF *p)
{
    return;
    if (p)
    {
        println("EPINF:{epara=%p,grpInf=%p}", p->epara, p->grpInf);
        if (p->epara)
        {
            TDLLEPARA *pTDLLEPARA = (TDLLEPARA *)p->epara;
            println("EPINF.epara:{based=%d,method=%d,grouped=%s}", pTDLLEPARA->based, pTDLLEPARA->method,
                    pTDLLEPARA->grouped ? "true" : "false");
        }
        if (p->grpInf)
        {
            TDLLGRPINF *pTDLLGRPINF = (TDLLGRPINF *)p->grpInf;
            println("EPINF.grpInf:{head=%p,len=%d,num=%p,*num=%d}", pTDLLGRPINF->head, pTDLLGRPINF->len,
                    pTDLLGRPINF->num, pTDLLGRPINF->num ? *pTDLLGRPINF->num : 0);
            if (pTDLLGRPINF->num && *pTDLLGRPINF->num > 0)
            {
                print4x(pTDLLGRPINF->head,
                        std::max(*pTDLLGRPINF->num * (int32_t)sizeof(TDLLGROUPListItem), pTDLLGRPINF->len),
                        "EPINF.grpInf.head");
            }
        }
    }
}
void printTDLLIDTINF(TDLLIDTINF *p)
{
    return;
    if (p)
    {
        println("IDTINF:{head=%p,len=%d,num=%p,*num=%d}", p->head, p->len, p->num, *p->num);
        if (p->num && *p->num > 0)
        {
            print4x(p->head, std::max(*p->num * (int32_t)sizeof(TDLLIDTListItem), p->len), "IDTINF.head");
        }
    }
}
void printTDLLRESINF(TDLLRESINF *p)
{
    return;
    if (p)
    {
        println("RESINF:{head=%p,len=%d,num=%p,*num=%d}", p->head, p->len, p->num, *p->num);
        if (p->num && *p->num > 0)
        {
            print4x(p->head, std::max(*p->num * (int32_t)sizeof(TDLLResultListItem), p->len), "RESINF.head");
        }
    }
}
void printTDLLSTDINF(TDLLSTDINF *p)
{
    return;
    if (p)
    {
        println("STDINF:{CurveType=%d,Zero=%d,amtInf=%p,cptInf=%p}", p->CurveType, p->Zero, p->amtInf, p->cptInf);
        if (p->amtInf)
        {
            TAMTINF *pTAMTINF = (TAMTINF *)p->amtInf;
            println("STDINF.amtInf:{head=%p,len=%d,num=%p,*num=%d}", pTAMTINF->head, pTAMTINF->len, pTAMTINF->num,
                    pTAMTINF->num ? *pTAMTINF->num : 0);
            if (pTAMTINF->num && *pTAMTINF->num > 0)
            {
                print4x(pTAMTINF->head,
                        std::max(*pTAMTINF->num * (int32_t)sizeof(TSTDAMTListItem), pTAMTINF->len),
                        "STDINF.amtInf.head");
            }
        }
        if (p->cptInf)
        {
            TCPTINF *pTCPTINF = (TCPTINF *)p->cptInf;
            println("STDINF.cptInf:{head=%p,len=%d,num=%p,*num=%d}", pTCPTINF->head, pTCPTINF->len, pTCPTINF->num,
                    pTCPTINF->num ? *pTCPTINF->num : 0);
            if (pTCPTINF->num && *pTCPTINF->num > 0)
            {
                print4x(pTCPTINF->head,
                        std::max(*pTCPTINF->num * (int32_t)sizeof(TSTDCPTListItem), pTCPTINF->len),
                        "STDINF.cptInf.head");
            }
        }
    }
}

void printConstant()
{
    return;
    double f = 1.878;
    int32_t fIntA = (int32_t)f;
    int32_t fIntB;
    std::memcpy(&fIntB, &f, sizeof(int32_t));

    println("f=%d  %d", fIntA, fIntB);

    println("sizeof(int32_t)=%d", sizeof(int32_t));
    println("sizeof(int32_t)=%d", sizeof(int32_t));
    println("sizeof(int32_t)=%d", sizeof(int32_t));
    println("sizeof(float)=%d", sizeof(float));
    println("sizeof(double)=%d", sizeof(double));

    println("--------------------------------\n");

    println("sizeof(CTickmarkManager)=%x", sizeof(CTickmarkManager));
    println("sizeof(CBuffer10Wrapper)=%x", sizeof(CBuffer10Wrapper));
    println("sizeof(CEventManager)=%x", sizeof(CEventManager));
    println("sizeof(CResultCaculator)=%x", sizeof(CResultCaculator));
    println("sizeof(CConcCaculator)=%x", sizeof(CConcCaculator));
    println("sizeof(CIndexWrapper)=%x", sizeof(CIndexWrapper));

    println("--------------------------------\n");

    println("sizeof(CTsmpBag)=%x", sizeof(CTsmpBag));
    println("sizeof(CIParaWrapper)=%x", sizeof(CIParaWrapper));
    println("sizeof(CTprgInfWrapper)=%x", sizeof(CTprgInfWrapper));
    println("sizeof(CEParaWrapper)=%x", sizeof(CEParaWrapper));
    println("sizeof(CGrpInfWrapper)=%x", sizeof(CGrpInfWrapper));
    println("sizeof(CIdtInfWrapper)=%x", sizeof(CIdtInfWrapper));
    println("sizeof(CResInfWrapper)=%x", sizeof(CResInfWrapper));
    println("sizeof(CAmtInfWrapper)=%x", sizeof(CAmtInfWrapper));
    println("sizeof(CCptInfWrapper)=%x", sizeof(CCptInfWrapper));
    println("sizeof(CStdInfManager)=%x", sizeof(CStdInfManager));
    println("sizeof(AnalExecutor)=%x", sizeof(AnalExecutor));

    println("--------------------------------\n");

    println("Format=%s", Format);
    println("aNumberOfPeaksO1_CN=%s", aNumberOfPeaksO1_CN);
    println("aNumberOfPeaksO2_CN=%s", aNumberOfPeaksO2_CN);
    println("aNumberOfPeaksO3_CN=%s", aNumberOfPeaksO3_CN);
    println("aNumberOfTangen_CN=%s", aNumberOfTangen_CN);
    println("aNumberOfSolven0_CN=%s", aNumberOfSolven0_CN);
    println("aNoEnoughMemory0_CN=%s", aNoEnoughMemory0_CN);
    println("aNumberOfTangen0_CN=%s", aNumberOfTangen0_CN);
    println("aNumberOfPeaksO0_CN=%s", aNumberOfPeaksO0_CN);
    println("aNoFindTheGoalP_CN=%s", aNoFindTheGoalP_CN);
    println("aThePeakStartMu_CN=%s", aThePeakStartMu_CN);
    println("aThePeakStartCa_CN=%s", aThePeakStartCa_CN);
    println("aNoFindTheGoalP0_CN=%s", aNoFindTheGoalP0_CN);
    println("aThePeakEndMust_CN=%s", aThePeakEndMust_CN);
    println("aThePeakStartCa0_CN=%s", aThePeakStartCa0_CN);
    println("aThereIsNoneOfO_CN=%s", aThereIsNoneOfO_CN);
    println("aCanTMoveTheSpl_CN=%s", aCanTMoveTheSpl_CN);
    println("aCanTMoveTheSpl0_CN=%s", aCanTMoveTheSpl0_CN);
    println("aNotLocateTheGo_CN=%s", aNotLocateTheGo_CN);
    println("aNotLocateTheGo0_CN=%s", aNotLocateTheGo0_CN);
    println("aCanTAddASplitI_CN=%s", aCanTAddASplitI_CN);
    println("aCanTAddASplitO_CN=%s", aCanTAddASplitO_CN);
    println("aCanTAddASplitO0_CN=%s", aCanTAddASplitO0_CN);
    println("aNotLocateTheGo1_CN=%s", aNotLocateTheGo1_CN);
    println("aNotLocateTheGo2_CN=%s", aNotLocateTheGo2_CN);
    println("aTheGoalTimeRan_CN=%s", aTheGoalTimeRan_CN);
    println("aCanTLocateTheG_CN=%s", aCanTLocateTheG_CN);
    println("aCanTRecogniseA_CN=%s", aCanTRecogniseA_CN);
    println("aThereIsNtAnyPe_CN=%s", aThereIsNtAnyPe_CN);
    println("aThereIsNtAnyPe0_CN=%s", aThereIsNtAnyPe0_CN);
    println("aThereIsNtAnyPe1_CN=%s", aThereIsNtAnyPe1_CN);
    println("aThereIsOnlyOne_CN=%s", aThereIsOnlyOne_CN);
    println("aThePeaksInside_CN=%s", aThePeaksInside_CN);
    println("aThereIsNtAnyPe2_CN=%s", aThereIsNtAnyPe2_CN);
    println("aCanTMakeTangen_CN=%s", aCanTMakeTangen_CN);
    println("aThereAreSomeTa_CN=%s", aThereAreSomeTa_CN);
    println("aThereIsNtAnyPe3_CN=%s", aThereIsNtAnyPe3_CN);
    println("aCanTMakeFrontT_CN=%s", aCanTMakeFrontT_CN);
    println("aThereAreSomeTa0_CN=%s", aThereAreSomeTa0_CN);
    println("aThereIsNtAnyPe4_CN=%s", aThereIsNtAnyPe4_CN);
    println("aThereIsNtAnyPe5_CN=%s", aThereIsNtAnyPe5_CN);
    println("aThereIsNtAnyPe6_CN=%s", aThereIsNtAnyPe6_CN);
    println("aThereIsNtAnyPe7_CN=%s", aThereIsNtAnyPe7_CN);
}

#if defined(_MSC_VER) && !defined(CHEM_DLL)
int32_t APIENTRY DllMain(HANDLE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/)
{
    // printConstant();
    println("analysis.dll!");
    // if (NULL == hmodule && !toggleVer)
    // {
    // 	int32_t k = 10;
    // 	double *dVal = new double[1];
    // 	*(__int64 *)dVal = 0x4059000000000000i64;
    // 	*(DWORD *)((BYTE *)dVal) = 0;
    // 	*(DWORD *)(((BYTE *)dVal) + 4) = 0;
    // 	println("LoadLibrary:analysisDLL_,k=%d,dVal=%lf", k, *dVal);
    // 	hmodule = LoadLibrary("analysisDLL_.dll");
    // 	println("LoadLibrary:hmodule=%p", hmodule);
    //        delete []dVal;
    // }
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}
#endif

// This is an example of an exported variable
ANALYSIS_API int32_t nAnalysis = 0;

// This is an example of an exported function.
ANALYSIS_API int32_t fnAnalysis(void)
{
    return 42;
}

#ifdef _MSC_VER

extern "C"
{
    ANALYSIS_API int32_t InitAnalPool(int32_t maxChannels, int32_t realChannels,
                                      void (*drawTickMark)(int32_t ch, int32_t time, TICKMARK tickmark));
    ANALYSIS_API int32_t ExitAnalPool();
    ANALYSIS_API int32_t GetAnalPoolVolume(int32_t *maxReal = NULL, int32_t *maxRedo = NULL);
    ANALYSIS_API int32_t OpenAnal(int32_t ch, TSMPBAG *smpBag, TDLLIPINF *ipInf, TDLLEPINF *epInf, TDLLIDTINF *idtInf,
                                  TDLLRESINF *resInf, TDLLSTDINF *stdInf = NULL);
    ANALYSIS_API int32_t CloseAnal(int32_t ch);
    ANALYSIS_API int32_t StartAnal(int32_t ch);
    ANALYSIS_API int32_t StopAnal(int32_t ch);
    ANALYSIS_API CODE ExecAnal(int32_t ch);
    ANALYSIS_API int32_t GetAnalTime(int32_t ch);
    ANALYSIS_API char *GetErrMsg(int32_t ch);
    ANALYSIS_API int32_t TickAnal(int32_t ch);
    ANALYSIS_API int32_t AnalOpened(int32_t ch);
    ANALYSIS_API int32_t AnalBusy(int32_t ch);
    ANALYSIS_API int32_t GetAnalOpened(int32_t **chArray);
    ANALYSIS_API int32_t GetAnalBusy(int32_t **chArray);
    ANALYSIS_API int32_t SetUkPkFactor(int32_t ch, TUkPkFactor *lpUkPkFactor);
    ANALYSIS_API int32_t SetIdtTimeOfs(int32_t ch, float fTimeOfs);
    ANALYSIS_API int32_t SetYMinUnit(int32_t ch, double yMinUnit);
    ANALYSIS_API int32_t SetIdtQualitMode(int32_t ch, int32_t nQualitMode, float fTimeWindow);
    ANALYSIS_API int32_t SetXMinUnitK(int32_t ch, double xMinUnitK);
#if defined(_WIN64) || defined(__LP64__) || defined(__x86_64__)
    ANALYSIS_API int32_t SetMiscellaneous(int32_t ch, uint64_t wParam, uint64_t lParam);
#else
    ANALYSIS_API int32_t SetMiscellaneous(int32_t ch, DWORD wParam, DWORD lParam);
#endif
    ANALYSIS_API int32_t EvalResult(TDLLRESINF *resInf, TDLLEPINF *epInf, TDLLIDTINF *idtInf, TDLLMETRIC *metric);
    ANALYSIS_API int32_t EvalColumnPerf(TDLLResultListItem *pHead, int32_t pCount, int32_t *smpHead, float freq);
    ANALYSIS_API double EvalKHeightW(TDLLResultListItem *pHead, int32_t *smpHead, double k, float freq, double *lpWL,
                                     double *lpWR);
    ANALYSIS_API int32_t EvalColumnPerfEx(TDLLResultListItem *pHead, int32_t pCount, int32_t *smpHead, float freq,
                                          double xMinUnitK);
    ANALYSIS_API double EvalKHeightWEx(TDLLResultListItem *pHead, int32_t *smpHead, double k, float freq, double xMinUnitK,
                                       double *lpWL, double *lpWR);
    ANALYSIS_API int32_t EvalGroup(TDLLGRPINF *grpInf, TDLLRESINF *resInf);
    ANALYSIS_API int32_t EvalCalibFact(TDLLSTDINF *stdInf, TEPara *epara, TDLLIDTINF *idtInf);
    ANALYSIS_API int32_t ManualPeakStart(int32_t ch, float startTime);
    ANALYSIS_API int32_t ManualPeakEnd(int32_t ch, float endTime);
    ANALYSIS_API int32_t ManualPeakMoveSplit(int32_t ch, float valleyTime);
    ANALYSIS_API int32_t ManualPeakAddSplit(int32_t ch, float splitTime);
    ANALYSIS_API int32_t ManualPeakDelSplit(int32_t ch, float splitTime);
    ANALYSIS_API int32_t ManualPeakAddOnlyOne(int32_t ch, float beginTime, float endTime);
    ANALYSIS_API int32_t ManualPeakDelete(int32_t ch, float beginTime, float endTime);
    ANALYSIS_API int32_t ManualBaseValley(int32_t ch, float beginTime, float endTime);
    ANALYSIS_API int32_t ManualBaseTogether(int32_t ch, float beginTime, float endTime);
    ANALYSIS_API int32_t ManualBaseTailTangent(int32_t ch, float beginTime, float endTime);
    ANALYSIS_API int32_t ManualBaseFrontTangent(int32_t ch, float beginTime, float endTime);
    ANALYSIS_API int32_t ManualBaseForwHori(int32_t ch, float beginTime, float endTime);
    ANALYSIS_API int32_t ManualBaseBackHori(int32_t ch, float beginTime, float endTime);
    ANALYSIS_API int32_t ManualParaWidth(int32_t ch, float beginTime, float endTime, float pkWidth);
    ANALYSIS_API int32_t ManualParaNoise(int32_t ch, float beginTime, float endTime, float pkNoise);
    ANALYSIS_API int32_t UpdateResult(int32_t ch, int32_t pStart, int32_t pEnd);
    ANALYSIS_API double CvtConcToAmt(double conc, TDLLMETRIC *metric, int32_t method);
    ANALYSIS_API double CvtConcToAmtByIstd(double conc, TDLLMETRIC *metric);
    ANALYSIS_API int32_t LearnAutoPara(AUTOPOOL *autoPool, float freq, AUTOPARA *autoPara);
    ANALYSIS_API int32_t MakeAutoPara(int32_t *buf, int32_t len, float freq, AUTOPARA *autoPara);
    ANALYSIS_API int32_t LearnAutoIPara(AUTOPOOL *autoPool, float freq, AUTOIPARA *autoIPara);
    ANALYSIS_API int32_t MakeAutoIPara(int32_t *buf, int32_t len, float freq, AUTOIPARA *autoIPara);
    ANALYSIS_API int32_t MdyAnalStopTime(int32_t ch, float fMinutes);
    ANALYSIS_API int32_t MdyPeakSmpHead(int32_t ch, int32_t *pSmpHead);
}
#endif

extern "C"
{
    int32_t InitAnalPool(int32_t maxChannels, int32_t realChannels,
                         void (*drawTickMark)(int32_t ch, int32_t time, TICKMARK tickmark))
    {
        println("InitAnalPool maxChannels=%d", maxChannels);
#ifdef _MSC_VER
        if (toggleVer)
        {
            return InitAnalPool_(maxChannels, realChannels, drawTickMark);
        }
        else if (NULL != hmodule)
        {
            InitAnalPoo_ fn = (InitAnalPoo_)GetProcAddress(hmodule, "InitAnalPoo_");
            if (NULL == fn)
            {
                fn = (InitAnalPoo_)GetProcAddress(hmodule, "InitAnalPool");
            }
            if (NULL != fn)
            {
                return fn(maxChannels, realChannels, drawTickMark);
            }
        }
        return false;
#else
        return InitAnalPool_(maxChannels, realChannels, drawTickMark);
#endif
    }

    int32_t ExitAnalPool()
    {
        println("ExitAnalPool");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ExitAnalPool_();
        }
        else if (NULL != hmodule)
        {
            ExitAnalPoo_ fn = (ExitAnalPoo_)GetProcAddress(hmodule, "ExitAnalPoo_");
            if (NULL == fn)
            {
                fn = (ExitAnalPoo_)GetProcAddress(hmodule, "ExitAnalPool");
            }
            if (NULL != fn)
            {
                return fn();
            }
        }
        return false;
#else
        return ExitAnalPool_();
#endif
    }
    int32_t GetAnalPoolVolume(int32_t *maxReal, int32_t *maxRedo)
    {
        println("GetAnalPoolVolume");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return GetAnalPoolVolume_(maxReal, maxRedo);
        }
        else if (NULL != hmodule)
        {
            GetAnalPoolVolum_ fn = (GetAnalPoolVolum_)GetProcAddress(hmodule, "GetAnalPoolVolum_");
            if (NULL == fn)
            {
                fn = (GetAnalPoolVolum_)GetProcAddress(hmodule, "GetAnalPoolVolume");
            }
            if (NULL != fn)
            {
                return fn(maxReal, maxRedo);
            }
        }
        return 0;
#else
        return GetAnalPoolVolume_(maxReal, maxRedo);
#endif
    }
    int32_t OpenAnal(int32_t ch, TSMPBAG *smpBag, TDLLIPINF *ipInf, TDLLEPINF *epInf, TDLLIDTINF *idtInf,
                     TDLLRESINF *resInf, TDLLSTDINF *stdInf)
    {
        println("OpenAnal --> ch=%d, smpBag=%p, ipInf=%p, epInf=%p, idtInf=%p, resInf=%p, stdInf=%p", ch, smpBag, ipInf,
                epInf, idtInf, resInf, stdInf);
        println("OpenAnal --> Time=%f, band=%f, Time=%f, band=%f", idtInf->head->Time, idtInf->head->band,
                idtInf->head->Time, idtInf->head->band);
        // std::cout << "222 --------------------------------------" << std::endl;
        // std::cout << "sizeof(TSMPBAG):" << sizeof( TSMPBAG ) << std::endl;
        // std::cout << "sizeof(TDLLMETRIC):" << sizeof( TDLLMETRIC ) << std::endl;
        // std::cout << "sizeof(TRAWBAG):" << sizeof( TRAWBAG ) << std::endl;

        // std::cout << "222 --------------------------------------" << std::endl;
        // std::cout << "sizeof(TDLLIPINF):" << sizeof( TDLLIPINF ) << std::endl;
        // std::cout << "sizeof(TIPara):" << sizeof( TIPara ) << std::endl;
        // std::cout << "sizeof(TDLLTPRGINF):" << sizeof( TDLLTPRGINF ) << std::endl;
        // std::cout << "sizeof(TDLLTPRGListItem):" << sizeof( TDLLTPRGListItem ) << std::endl;

        // std::cout << "222 --------------------------------------" << std::endl;
        // std::cout << "sizeof(TDLLEPINF):" << sizeof( TDLLEPINF ) << std::endl;
        // std::cout << "sizeof(TDLLEPARA):" << sizeof( TDLLEPARA ) << std::endl;
        // std::cout << "sizeof(TDLLGRPINF):" << sizeof( TDLLGRPINF ) << std::endl;
        // std::cout << "sizeof(TDLLGROUPListItem):" << sizeof( TDLLGROUPListItem ) << std::endl;

        // std::cout << "222 --------------------------------------" << std::endl;
        // std::cout << "sizeof(TDLLRESINF):" << sizeof( TDLLRESINF ) << std::endl;
        // std::cout << "sizeof(TDLLResultListItem):" << sizeof( TDLLResultListItem ) << std::endl;

        // std::cout << "222 --------------------------------------" << std::endl;
        // std::cout << "sizeof(TDLLSTDINF):" << sizeof( TDLLSTDINF ) << std::endl;
        // std::cout << "sizeof(TAMTINF):" << sizeof( TAMTINF ) << std::endl;
        // std::cout << "sizeof(TSTDAMTListItem):" << sizeof( TSTDAMTListItem ) << std::endl;
        // std::cout << "sizeof(TDLLMETRIC):" << sizeof( TDLLMETRIC ) << std::endl;
        // std::cout << "sizeof(TCPTINF):" << sizeof( TCPTINF ) << std::endl;
        // std::cout << "sizeof(TSTDCPTListItem):" << sizeof( TSTDCPTListItem ) << std::endl;

        old_smpBag[ch] = smpBag;
        old_ipInf[ch] = ipInf;
        old_epInf[ch] = epInf;
        old_idtInf[ch] = idtInf;
        old_resInf[ch] = resInf;
        old_stdInf[ch] = stdInf;
#ifdef _MSC_VER
        int32_t result = false;
        if (toggleVer)
        {
            result = OpenAnal_(ch, smpBag, ipInf, epInf, idtInf, resInf, stdInf);
        }
        else if (NULL != hmodule)
        {
            OpenAna_ fn = (OpenAna_)GetProcAddress(hmodule, "OpenAna_");
            if (NULL == fn)
            {
                fn = (OpenAna_)GetProcAddress(hmodule, "OpenAnal");
            }
            if (NULL != fn)
            {
                result = fn(ch, smpBag, ipInf, epInf, idtInf, resInf, stdInf);
            }
        }
        println("OpenAnal <-- result=%d", result);
        return result;
#else
        return OpenAnal_(ch, smpBag, ipInf, epInf, idtInf, resInf, stdInf);
#endif
    }
    int32_t CloseAnal(int32_t ch)
    {
        println("CloseAnal");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return CloseAnal_(ch);
        }
        else if (NULL != hmodule)
        {
            CloseAna_ fn = (CloseAna_)GetProcAddress(hmodule, "CloseAna_");
            if (NULL == fn)
            {
                fn = (CloseAna_)GetProcAddress(hmodule, "CloseAnal");
            }
            if (NULL != fn)
            {
                return fn(ch);
            }
        }
        return false;
#else
        return CloseAnal_(ch);
#endif
    }
    int32_t StartAnal(int32_t ch)
    {
        println("StartAnal --> ch=%d", ch);
#ifdef _MSC_VER
        int32_t result = false;
        if (toggleVer)
        {
            result = StartAnal_(ch);
        }
        else if (NULL != hmodule)
        {
            StartAna_ fn = (StartAna_)GetProcAddress(hmodule, "StartAna_");
            if (NULL == fn)
            {
                fn = (StartAna_)GetProcAddress(hmodule, "StartAnal");
            }
            if (NULL != fn)
            {
                result = fn(ch);
            }
        }
        println("StartAnal <-- result=%d", result);
        return result;
#else
        return StartAnal_(ch);
#endif
    }
    int32_t StopAnal(int32_t ch)
    {
        println("StopAnal");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return StopAnal_(ch);
        }
        else if (NULL != hmodule)
        {
            StopAna_ fn = (StopAna_)GetProcAddress(hmodule, "StopAna_");
            if (NULL == fn)
            {
                fn = (StopAna_)GetProcAddress(hmodule, "StopAnal");
            }
            if (NULL != fn)
            {
                return fn(ch);
            }
        }
        return false;
#else
        return StopAnal_(ch);
#endif
    }
    CODE ExecAnal(int32_t ch)
    {
        println("ExecAnal 111--> ch=%d", ch);
#ifdef _MSC_VER
        CODE result = ANAL_NOP;
        if (toggleVer)
        {
            result = ExecAnal_(ch);
        }
        else if (NULL != hmodule)
        {
            ExecAna_ fn = (ExecAna_)GetProcAddress(hmodule, "ExecAna_");
            if (NULL == fn)
            {
                fn = (ExecAna_)GetProcAddress(hmodule, "ExecAnal");
            }
            if (NULL != fn)
            {
                result = fn(ch);
            }
        }
        println("ExecAnal <-- result=%d", result);
        // printTSMPBAG(old_smpBag[ch]);
        // printTDLLIPINF(old_ipInf[ch]);
        // printTDLLEPINF(old_epInf[ch]);
        // printTDLLIDTINF(old_idtInf[ch]);
        // printTDLLRESINF(old_resInf[ch]);
        // printTDLLSTDINF(old_stdInf[ch]);

        return result;
#else
        return ExecAnal_(ch);
#endif
    }
    int32_t GetAnalTime(int32_t ch)
    {
        println("GetAnalTime");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return GetAnalTime_(ch);
        }
        else if (NULL != hmodule)
        {
            GetAnalTim_ fn = (GetAnalTim_)GetProcAddress(hmodule, "GetAnalTim_");
            if (NULL == fn)
            {
                fn = (GetAnalTim_)GetProcAddress(hmodule, "GetAnalTime");
            }
            if (NULL != fn)
            {
                return fn(ch);
            }
        }
        return false;
#else
        return GetAnalTime_(ch);
#endif
    }
    char *GetErrMsg(int32_t ch)
    {
        println("GetErrMsg ch=%d hmodule=%p", ch, hmodule);
#ifdef _MSC_VER
        if (toggleVer)
        {
            char *ret = GetErrMsg_(ch);
            println("GetErrMsg ret=%s", ret);
            return ret;
        }
        else if (NULL != hmodule)
        {
            GetErrMs_ fn = (GetErrMs_)GetProcAddress(hmodule, "GetErrMs_");
            println("GetErrMsg fn=%p", fn);
            if (NULL == fn)
            {
                fn = (GetErrMs_)GetProcAddress(hmodule, "GetErrMsg");
            }
            if (NULL != fn)
            {
                char *ret = fn(ch);
                println("GetErrMsg ret=%s", ret);
                return ret;
            }
        }
        return NULL;
#else
        return GetErrMsg_(ch);
#endif
    }
    int32_t TickAnal(int32_t ch)
    {
        println("TickAnal");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return TickAnal_(ch);
        }
        else if (NULL != hmodule)
        {
            TickAna_ fn = (TickAna_)GetProcAddress(hmodule, "TickAna_");
            if (NULL == fn)
            {
                fn = (TickAna_)GetProcAddress(hmodule, "TickAnal");
            }
            if (NULL != fn)
            {
                return fn(ch);
            }
        }
        return false;
#else
        return TickAnal_(ch);
#endif
    }
    int32_t AnalOpened(int32_t ch)
    {
        println("AnalOpened");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return AnalOpened_(ch);
        }
        else if (NULL != hmodule)
        {
            AnalOpene_ fn = (AnalOpene_)GetProcAddress(hmodule, "AnalOpene_");
            if (NULL == fn)
            {
                fn = (AnalOpene_)GetProcAddress(hmodule, "AnalOpened");
            }
            if (NULL != fn)
            {
                return fn(ch);
            }
        }
        return false;
#else
        return AnalOpened_(ch);
#endif
    }
    int32_t AnalBusy(int32_t ch)
    {
        println("AnalBusy");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return AnalBusy_(ch);
        }
        else if (NULL != hmodule)
        {
            AnalBus_ fn = (AnalBus_)GetProcAddress(hmodule, "AnalBus_");
            if (NULL == fn)
            {
                fn = (AnalBus_)GetProcAddress(hmodule, "AnalBusy");
            }
            if (NULL != fn)
            {
                return fn(ch);
            }
        }
        return false;
#else
        return AnalBusy_(ch);
#endif
    }
    int32_t GetAnalOpened(int32_t **chArray)
    {
        println("GetAnalOpened");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return GetAnalOpened_(chArray);
        }
        else if (NULL != hmodule)
        {
            GetAnalOpene_ fn = (GetAnalOpene_)GetProcAddress(hmodule, "GetAnalOpene_");
            if (NULL == fn)
            {
                fn = (GetAnalOpene_)GetProcAddress(hmodule, "GetAnalOpened");
            }
            if (NULL != fn)
            {
                return fn(chArray);
            }
        }
        return 0;
#else
        return GetAnalOpened_(chArray);
#endif
    }
    int32_t GetAnalBusy(int32_t **chArray)
    {
        println("GetAnalBusy");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return GetAnalBusy_(chArray);
        }
        else if (NULL != hmodule)
        {
            GetAnalBus_ fn = (GetAnalBus_)GetProcAddress(hmodule, "GetAnalBus_");
            if (NULL == fn)
            {
                fn = (GetAnalBus_)GetProcAddress(hmodule, "GetAnalBusy");
            }
            if (NULL != fn)
            {
                return fn(chArray);
            }
        }
        return 0;
#else
        return GetAnalBusy_(chArray);
#endif
    }
    int32_t SetUkPkFactor(int32_t ch, TUkPkFactor *lpUkPkFactor)
    {
        println("SetUkPkFactor");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return SetUkPkFactor_(ch, lpUkPkFactor);
        }
        else if (NULL != hmodule)
        {
            SetUkPkFacto_ fn = (SetUkPkFacto_)GetProcAddress(hmodule, "SetUkPkFacto_");
            if (NULL == fn)
            {
                fn = (SetUkPkFacto_)GetProcAddress(hmodule, "SetUkPkFactor");
            }
            if (NULL != fn)
            {
                return fn(ch, lpUkPkFactor);
            }
        }
        return false;
#else
        return SetUkPkFactor_(ch, lpUkPkFactor);
#endif
    }
    int32_t SetIdtTimeOfs(int32_t ch, float fTimeOfs)
    {
        println("SetIdtTimeOfs");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return SetIdtTimeOfs_(ch, fTimeOfs);
        }
        else if (NULL != hmodule)
        {
            SetIdtTimeOf_ fn = (SetIdtTimeOf_)GetProcAddress(hmodule, "SetIdtTimeOf_");
            if (NULL == fn)
            {
                fn = (SetIdtTimeOf_)GetProcAddress(hmodule, "SetIdtTimeOfs");
            }
            if (NULL != fn)
            {
                return fn(ch, fTimeOfs);
            }
        }
        return false;
#else
        return SetIdtTimeOfs_(ch, fTimeOfs);
#endif
    }
    int32_t SetYMinUnit(int32_t ch, double yMinUnit)
    {
        println("SetYMinUnit");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return SetYMinUnit_(ch, yMinUnit);
        }
        else if (NULL != hmodule)
        {
            SetYMinUni_ fn = (SetYMinUni_)GetProcAddress(hmodule, "SetYMinUni_");
            if (NULL == fn)
            {
                fn = (SetYMinUni_)GetProcAddress(hmodule, "SetYMinUnit");
            }
            if (NULL != fn)
            {
                return fn(ch, yMinUnit);
            }
        }
        return false;
#else
        return SetYMinUnit_(ch, yMinUnit);
#endif
    }
    int32_t SetIdtQualitMode(int32_t ch, int32_t nQualitMode, float fTimeWindow)
    {
        println("SetIdtQualitMode");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return SetIdtQualitMode_(ch, nQualitMode, fTimeWindow);
        }
        else if (NULL != hmodule)
        {
            SetIdtQualitMod_ fn = (SetIdtQualitMod_)GetProcAddress(hmodule, "SetIdtQualitMod_");
            if (NULL == fn)
            {
                fn = (SetIdtQualitMod_)GetProcAddress(hmodule, "SetIdtQualitMode");
            }
            if (NULL != fn)
            {
                return fn(ch, nQualitMode, fTimeWindow);
            }
        }
        return false;
#else
        return SetIdtQualitMode_(ch, nQualitMode, fTimeWindow);
#endif
    }
    int32_t SetXMinUnitK(int32_t ch, double xMinUnitK)
    {
        println("SetXMinUnitK");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return SetXMinUnitK_(ch, xMinUnitK);
        }
        else if (NULL != hmodule)
        {
            SetXMinUnit_ fn = (SetXMinUnit_)GetProcAddress(hmodule, "SetXMinUnit_");
            if (NULL == fn)
            {
                fn = (SetXMinUnit_)GetProcAddress(hmodule, "SetXMinUnitK");
            }
            if (NULL != fn)
            {
                return fn(ch, xMinUnitK);
            }
        }
        return false;
#else
        return SetXMinUnitK_(ch, xMinUnitK);
#endif
    }
#if defined(_WIN64) || defined(__LP64__) || defined(__x86_64__)
    int32_t SetMiscellaneous(int32_t ch, uint64_t wParam, uint64_t lParam)
#else
    int32_t SetMiscellaneous(int32_t ch, DWORD wParam, DWORD lParam)
#endif
    {
        println("SetMiscellaneous --> ch=%d, wParam=%p lParam=%p", ch, wParam, lParam);
#ifdef _MSC_VER
        int32_t result = false;
        if (toggleVer)
        {
            result = SetMiscellaneous_(ch, wParam, lParam);
        }
        else if (NULL != hmodule)
        {
            SetMiscellaneou_ fn = (SetMiscellaneou_)GetProcAddress(hmodule, "SetMiscellaneou_");
            if (NULL == fn)
            {
                fn = (SetMiscellaneou_)GetProcAddress(hmodule, "SetMiscellaneous");
            }
            if (NULL != fn)
            {
                result = fn(ch, (DWORD)wParam, (DWORD)lParam);
            }
        }
        println("SetMiscellaneous <-- result=%d", result);
        return result;
#else
        return SetMiscellaneous_(ch, wParam, lParam);
#endif
    }
    int32_t EvalResult(TDLLRESINF *resInf, TDLLEPINF *epInf, TDLLIDTINF *idtInf, TDLLMETRIC *metric)
    {
        println("EvalResult");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return EvalResult_(resInf, epInf, idtInf, metric);
        }
        else if (NULL != hmodule)
        {
            EvalResul_ fn = (EvalResul_)GetProcAddress(hmodule, "EvalResul_");
            if (NULL == fn)
            {
                fn = (EvalResul_)GetProcAddress(hmodule, "EvalResult");
            }
            if (NULL != fn)
            {
                return fn(resInf, epInf, idtInf, metric);
            }
        }
        return false;
#else
        return EvalResult_(resInf, epInf, idtInf, metric);
#endif
    }
    int32_t EvalColumnPerf(TDLLResultListItem *pHead, int32_t pCount, int32_t *smpHead, float freq)
    {
        println("EvalColumnPerf");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return EvalColumnPerf_(pHead, pCount, smpHead, freq);
        }
        else if (NULL != hmodule)
        {
            EvalColumnPer_ fn = (EvalColumnPer_)GetProcAddress(hmodule, "EvalColumnPer_");
            if (NULL == fn)
            {
                fn = (EvalColumnPer_)GetProcAddress(hmodule, "EvalColumnPerf");
            }
            if (NULL != fn)
            {
                return fn(pHead, pCount, smpHead, freq);
            }
        }
        return false;
#else
        return EvalColumnPerf_(pHead, pCount, smpHead, freq);
#endif
    }
    double EvalKHeightW(TDLLResultListItem *pHead, int32_t *smpHead, double k, float freq, double *lpWL, double *lpWR)
    {
        println("EvalKHeightW");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return EvalKHeightW_(pHead, smpHead, k, freq, lpWL, lpWR);
        }
        else if (NULL != hmodule)
        {
            EvalKHeight_ fn = (EvalKHeight_)GetProcAddress(hmodule, "EvalKHeight_");
            if (NULL == fn)
            {
                fn = (EvalKHeight_)GetProcAddress(hmodule, "EvalKHeightW");
            }
            if (NULL != fn)
            {
                return fn(pHead, smpHead, k, freq, lpWL, lpWR);
            }
        }
        return 0;
#else
        return EvalKHeightW_(pHead, smpHead, k, freq, lpWL, lpWR);
#endif
    }
    int32_t EvalColumnPerfEx(TDLLResultListItem *pHead, int32_t pCount, int32_t *smpHead, float freq, double xMinUnitK)
    {
        println("EvalColumnPerfEx");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return EvalColumnPerfEx_(pHead, pCount, smpHead, freq, xMinUnitK);
        }
        else if (NULL != hmodule)
        {
            EvalColumnPerfE_ fn = (EvalColumnPerfE_)GetProcAddress(hmodule, "EvalColumnPerfE_");
            if (NULL == fn)
            {
                fn = (EvalColumnPerfE_)GetProcAddress(hmodule, "EvalColumnPerfEx");
            }
            if (NULL != fn)
            {
                return fn(pHead, pCount, smpHead, freq, xMinUnitK);
            }
        }
        return false;
#else
        return EvalColumnPerfEx_(pHead, pCount, smpHead, freq, xMinUnitK);
#endif
    }
    double EvalKHeightWEx(TDLLResultListItem *pHead, int32_t *smpHead, double k, float freq, double xMinUnitK,
                          double *lpWL, double *lpWR)
    {
        double WL = 0.0;
        double WR = 0.0;
        if (lpWL == NULL)
            lpWL = &WL;
        if (lpWR == NULL)
            lpWR = &WR;

#ifdef _MSC_VER
        double result = 0;
        println("EvalKHeightWEx -> k=%lf freq=%f xMinUnitK=%lf *lpWL=%lf *lpWR=%lf", k, freq, xMinUnitK,
                lpWL != NULL ? *lpWL : 0, lpWR != NULL ? *lpWR : 0);
        if (toggleVer)
        {
            result = EvalKHeightWEx_(pHead, smpHead, k, freq, xMinUnitK, lpWL, lpWR);
        }
        else if (NULL != hmodule)
        {
            EvalKHeightWE_ fn = (EvalKHeightWE_)GetProcAddress(hmodule, "EvalKHeightWE_");
            if (NULL == fn)
            {
                fn = (EvalKHeightWE_)GetProcAddress(hmodule, "EvalKHeightWEx");
            }
            if (NULL != fn)
            {
                result = fn(pHead, smpHead, k, freq, xMinUnitK, lpWL, lpWR);
            }
        }
        println("EvalKHeightWEx <- result=%lf *lpWL=%lf *lpWR=%lf", result, *lpWL, *lpWR);
        return result;
#else
        return EvalKHeightWEx_(pHead, smpHead, k, freq, xMinUnitK, lpWL, lpWR);
#endif
    }
    int32_t EvalGroup(TDLLGRPINF *grpInf, TDLLRESINF *resInf)
    {
        println("EvalGroup");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return EvalGroup_(grpInf, resInf);
        }
        else if (NULL != hmodule)
        {
            EvalGrou_ fn = (EvalGrou_)GetProcAddress(hmodule, "EvalGrou_");
            if (NULL == fn)
            {
                fn = (EvalGrou_)GetProcAddress(hmodule, "EvalGroup");
            }
            if (NULL != fn)
            {
                return fn(grpInf, resInf);
            }
        }
        return false;
#else
        return EvalGroup_(grpInf, resInf);
#endif
    }
    ////
    int32_t EvalCalibFact(TDLLSTDINF *stdInf, TEPara *epara, TDLLIDTINF *idtInf)
    {
        print4x(idtInf->head, idtInf->len * *idtInf->num, "in");

#ifdef _MSC_VER
        int32_t result = false;
        if (toggleVer)
        {
            result = EvalCalibFact_(stdInf, epara, idtInf);
        }
        else if (NULL != hmodule)
        {
            EvalCalibFac_ fn = (EvalCalibFac_)GetProcAddress(hmodule, "EvalCalibFac_");
            if (NULL == fn)
            {
                fn = (EvalCalibFac_)GetProcAddress(hmodule, "EvalCalibFact");
            }
            if (NULL != fn)
            {
                result = fn(stdInf, epara, idtInf);
            }
        }
        print4x(idtInf->head, idtInf->len * *idtInf->num, "out");
        // printTDLLSTDINF(stdInf);
        // printTDLLIDTINF(idtInf);
        return result;
#else
        return EvalCalibFact_(stdInf, epara, idtInf);
#endif
    }
    int32_t ManualPeakStart(int32_t ch, float startTime)
    {
        println("ManualPeakStart");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualPeakStart_(ch, startTime);
        }
        else if (NULL != hmodule)
        {
            ManualPeakStar_ fn = (ManualPeakStar_)GetProcAddress(hmodule, "ManualPeakStar_");
            if (NULL == fn)
            {
                fn = (ManualPeakStar_)GetProcAddress(hmodule, "ManualPeakStart");
            }
            if (NULL != fn)
            {
                return fn(ch, startTime);
            }
        }
        return false;
#else
        return ManualPeakStart_(ch, startTime);
#endif
    }
    int32_t ManualPeakEnd(int32_t ch, float endTime)
    {
        println("ManualPeakEnd");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualPeakEnd_(ch, endTime);
        }
        else if (NULL != hmodule)
        {
            ManualPeakEn_ fn = (ManualPeakEn_)GetProcAddress(hmodule, "ManualPeakEn_");
            if (NULL == fn)
            {
                fn = (ManualPeakEn_)GetProcAddress(hmodule, "ManualPeakEnd");
            }
            if (NULL != fn)
            {
                return fn(ch, endTime);
            }
        }
        return false;
#else
        return ManualPeakEnd_(ch, endTime);
#endif
    }
    int32_t ManualPeakMoveSplit(int32_t ch, float valleyTime)
    {
        println("ManualPeakMoveSplit");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualPeakMoveSplit_(ch, valleyTime);
        }
        else if (NULL != hmodule)
        {
            ManualPeakMoveSpli_ fn = (ManualPeakMoveSpli_)GetProcAddress(hmodule, "ManualPeakMoveSpli_");
            if (NULL == fn)
            {
                fn = (ManualPeakMoveSpli_)GetProcAddress(hmodule, "ManualPeakMoveSplit");
            }
            if (NULL != fn)
            {
                return fn(ch, valleyTime);
            }
        }
        return false;
#else
        return ManualPeakMoveSplit_(ch, valleyTime);
#endif
    }
    int32_t ManualPeakAddSplit(int32_t ch, float splitTime)
    {
        println("ManualPeakAddSplit");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualPeakAddSplit_(ch, splitTime);
        }
        else if (NULL != hmodule)
        {
            ManualPeakAddSpli_ fn = (ManualPeakAddSpli_)GetProcAddress(hmodule, "ManualPeakAddSpli_");
            if (NULL == fn)
            {
                fn = (ManualPeakAddSpli_)GetProcAddress(hmodule, "ManualPeakAddSplit");
            }
            if (NULL != fn)
            {
                return fn(ch, splitTime);
            }
        }
        return false;
#else
        return ManualPeakAddSplit_(ch, splitTime);
#endif
    }
    int32_t ManualPeakDelSplit(int32_t ch, float splitTime)
    {
        println("ManualPeakDelSplit");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualPeakDelSplit_(ch, splitTime);
        }
        else if (NULL != hmodule)
        {
            ManualPeakDelSpli_ fn = (ManualPeakDelSpli_)GetProcAddress(hmodule, "ManualPeakDelSpli_");
            if (NULL == fn)
            {
                fn = (ManualPeakDelSpli_)GetProcAddress(hmodule, "ManualPeakDelSplit");
            }
            if (NULL != fn)
            {
                return fn(ch, splitTime);
            }
        }
        return false;
#else
        return ManualPeakDelSplit_(ch, splitTime);
#endif
    }
    int32_t ManualPeakAddOnlyOne(int32_t ch, float beginTime, float endTime)
    {
        println("ManualPeakAddOnlyOne");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualPeakAddOnlyOne_(ch, beginTime, endTime);
        }
        else if (NULL != hmodule)
        {
            ManualPeakAddOnlyOn_ fn = (ManualPeakAddOnlyOn_)GetProcAddress(hmodule, "ManualPeakAddOnlyOn_");
            if (NULL == fn)
            {
                fn = (ManualPeakAddOnlyOn_)GetProcAddress(hmodule, "ManualPeakAddOnlyOne");
            }
            if (NULL != fn)
            {
                return fn(ch, beginTime, endTime);
            }
        }
        return false;
#else
        return ManualPeakAddOnlyOne_(ch, beginTime, endTime);
#endif
    }
    int32_t ManualPeakDelete(int32_t ch, float beginTime, float endTime)
    {
        println("ManualPeakDelete");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualPeakDelete_(ch, beginTime, endTime);
        }
        else if (NULL != hmodule)
        {
            ManualPeakDelet_ fn = (ManualPeakDelet_)GetProcAddress(hmodule, "ManualPeakDelet_");
            if (NULL == fn)
            {
                fn = (ManualPeakDelet_)GetProcAddress(hmodule, "ManualPeakDelete");
            }
            if (NULL != fn)
            {
                return fn(ch, beginTime, endTime);
            }
        }
        return false;
#else
        return ManualPeakDelete_(ch, beginTime, endTime);
#endif
    }
    int32_t ManualBaseValley(int32_t ch, float beginTime, float endTime)
    {
        println("ManualBaseValley");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualBaseValley_(ch, beginTime, endTime);
        }
        else if (NULL != hmodule)
        {
            ManualBaseValle_ fn = (ManualBaseValle_)GetProcAddress(hmodule, "ManualBaseValle_");
            if (NULL == fn)
            {
                fn = (ManualBaseValle_)GetProcAddress(hmodule, "ManualBaseValley");
            }
            if (NULL != fn)
            {
                return fn(ch, beginTime, endTime);
            }
        }
        return false;
#else
        return ManualBaseValley_(ch, beginTime, endTime);
#endif
    }
    int32_t ManualBaseTogether(int32_t ch, float beginTime, float endTime)
    {
        println("ManualBaseTogether");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualBaseTogether_(ch, beginTime, endTime);
        }
        else if (NULL != hmodule)
        {
            ManualBaseTogethe_ fn = (ManualBaseTogethe_)GetProcAddress(hmodule, "ManualBaseTogethe_");
            if (NULL == fn)
            {
                fn = (ManualBaseTogethe_)GetProcAddress(hmodule, "ManualBaseTogether");
            }
            if (NULL != fn)
            {
                return fn(ch, beginTime, endTime);
            }
        }
        return false;
#else
        return ManualBaseTogether_(ch, beginTime, endTime);
#endif
    }
    int32_t ManualBaseTailTangent(int32_t ch, float beginTime, float endTime)
    {
        println("ManualBaseTailTangent");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualBaseTailTangent_(ch, beginTime, endTime);
        }
        else if (NULL != hmodule)
        {
            ManualBaseTailTangen_ fn = (ManualBaseTailTangen_)GetProcAddress(hmodule, "ManualBaseTailTangen_");
            if (NULL == fn)
            {
                fn = (ManualBaseTailTangen_)GetProcAddress(hmodule, "ManualBaseTailTangent");
            }
            if (NULL != fn)
            {
                return fn(ch, beginTime, endTime);
            }
        }
        return false;
#else
        return ManualBaseTailTangent_(ch, beginTime, endTime);
#endif
    }
    int32_t ManualBaseFrontTangent(int32_t ch, float beginTime, float endTime)
    {
        println("ManualBaseFrontTangent");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualBaseFrontTangent_(ch, beginTime, endTime);
        }
        else if (NULL != hmodule)
        {
            ManualBaseFrontTangen_ fn = (ManualBaseFrontTangen_)GetProcAddress(hmodule, "ManualBaseFrontTangen_");
            if (NULL == fn)
            {
                fn = (ManualBaseFrontTangen_)GetProcAddress(hmodule, "ManualBaseFrontTangent");
            }
            if (NULL != fn)
            {
                return fn(ch, beginTime, endTime);
            }
        }
        return false;
#else
        return ManualBaseFrontTangent_(ch, beginTime, endTime);
#endif
    }
    int32_t ManualBaseForwHori(int32_t ch, float beginTime, float endTime)
    {
        println("ManualBaseForwHori");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualBaseForwHori_(ch, beginTime, endTime);
        }
        else if (NULL != hmodule)
        {
            ManualBaseForwHor_ fn = (ManualBaseForwHor_)GetProcAddress(hmodule, "ManualBaseForwHor_");
            if (NULL == fn)
            {
                fn = (ManualBaseForwHor_)GetProcAddress(hmodule, "ManualBaseForwHori");
            }
            if (NULL != fn)
            {
                return fn(ch, beginTime, endTime);
            }
        }
        return false;
#else
        return ManualBaseForwHori_(ch, beginTime, endTime);
#endif
    }
    int32_t ManualBaseBackHori(int32_t ch, float beginTime, float endTime)
    {
        println("ManualBaseBackHori");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualBaseBackHori_(ch, beginTime, endTime);
        }
        else if (NULL != hmodule)
        {
            ManualBaseBackHor_ fn = (ManualBaseBackHor_)GetProcAddress(hmodule, "ManualBaseBackHor_");
            if (NULL == fn)
            {
                fn = (ManualBaseBackHor_)GetProcAddress(hmodule, "ManualBaseBackHori");
            }
            if (NULL != fn)
            {
                return fn(ch, beginTime, endTime);
            }
        }
        return false;
#else
        return ManualBaseBackHori_(ch, beginTime, endTime);
#endif
    }
    int32_t ManualParaWidth(int32_t ch, float beginTime, float endTime, float pkWidth)
    {
        println("ManualParaWidth");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualParaWidth_(ch, beginTime, endTime, pkWidth);
        }
        else if (NULL != hmodule)
        {
            ManualParaWidt_ fn = (ManualParaWidt_)GetProcAddress(hmodule, "ManualParaWidt_");
            if (NULL == fn)
            {
                fn = (ManualParaWidt_)GetProcAddress(hmodule, "ManualParaWidth");
            }
            if (NULL != fn)
            {
                return fn(ch, beginTime, endTime, pkWidth);
            }
        }
        return false;
#else
        return ManualParaWidth_(ch, beginTime, endTime, pkWidth);
#endif
    }
    int32_t ManualParaNoise(int32_t ch, float beginTime, float endTime, float pkNoise)
    {
        println("ManualParaNoise");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return ManualParaNoise_(ch, beginTime, endTime, pkNoise);
        }
        else if (NULL != hmodule)
        {
            ManualParaNois_ fn = (ManualParaNois_)GetProcAddress(hmodule, "ManualParaNois_");
            if (NULL == fn)
            {
                fn = (ManualParaNois_)GetProcAddress(hmodule, "ManualParaNoise");
            }
            if (NULL != fn)
            {
                return fn(ch, beginTime, endTime, pkNoise);
            }
        }
        return false;
#else
        return ManualParaNoise_(ch, beginTime, endTime, pkNoise);
#endif
    }

#ifdef _MSC_VER
    int32_t UpdateResult(int32_t ch, int32_t pStart, int32_t pEnd)
#else
    int32_t UpdateResult(int32_t, int32_t, int32_t)
#endif
    {
        println("UpdateResult");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return false;
        }
        else if (NULL != hmodule)
        {
            UpdateResul_ fn = (UpdateResul_)GetProcAddress(hmodule, "UpdateResul_");
            if (NULL == fn)
            {
                fn = (UpdateResul_)GetProcAddress(hmodule, "UpdateResult");
            }
            if (NULL != fn)
            {
                return fn(ch, pStart, pEnd);
            }
        }
        return false;
#else
        return false;
#endif
    }
    double CvtConcToAmt(double conc, TDLLMETRIC *metric, int32_t method)
    {
        println("CvtConcToAmt");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return CvtConcToAmt_(conc, metric, method);
        }
        else if (NULL != hmodule)
        {
            CvtConcToAm_ fn = (CvtConcToAm_)GetProcAddress(hmodule, "CvtConcToAm_");
            if (NULL == fn)
            {
                fn = (CvtConcToAm_)GetProcAddress(hmodule, "CvtConcToAmt");
            }
            if (NULL != fn)
            {
                return fn(conc, metric, method);
            }
        }
        return 0;
#else
        return CvtConcToAmt_(conc, metric, method);
#endif
    }
    double CvtConcToAmtByIstd(double conc, TDLLMETRIC *metric)
    {
        println("CvtConcToAmtByIstd");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return CvtConcToAmtByIstd_(conc, metric);
        }
        else if (NULL != hmodule)
        {
            CvtConcToAmtByIst_ fn = (CvtConcToAmtByIst_)GetProcAddress(hmodule, "CvtConcToAmtByIst_");
            if (NULL == fn)
            {
                fn = (CvtConcToAmtByIst_)GetProcAddress(hmodule, "CvtConcToAmtByIstd");
            }
            if (NULL != fn)
            {
                return fn(conc, metric);
            }
        }
        return 0;
#else
        return CvtConcToAmtByIstd_(conc, metric);
#endif
    }
    int32_t LearnAutoPara(AUTOPOOL *autoPool, float freq, AUTOPARA *autoPara)
    {
        println("LearnAutoPara");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return LearnAutoPara_(autoPool, freq, autoPara);
        }
        else if (NULL != hmodule)
        {
            LearnAutoPar_ fn = (LearnAutoPar_)GetProcAddress(hmodule, "LearnAutoPar_");
            if (NULL == fn)
            {
                fn = (LearnAutoPar_)GetProcAddress(hmodule, "LearnAutoPara");
            }
            if (NULL != fn)
            {
                return fn(autoPool, freq, autoPara);
            }
        }
        return false;
#else
        return LearnAutoPara_(autoPool, freq, autoPara);
#endif
    }
    int32_t MakeAutoPara(int32_t *buf, int32_t len, float freq, AUTOPARA *autoPara)
    {
        println("MakeAutoPara");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return MakeAutoPara_(buf, len, freq, autoPara);
        }
        else if (NULL != hmodule)
        {
            MakeAutoPar_ fn = (MakeAutoPar_)GetProcAddress(hmodule, "MakeAutoPar_");
            if (NULL == fn)
            {
                fn = (MakeAutoPar_)GetProcAddress(hmodule, "MakeAutoPara");
            }
            if (NULL != fn)
            {
                return fn(buf, len, freq, autoPara);
            }
        }
        return false;
#else
        return MakeAutoPara_(buf, len, freq, autoPara);
#endif
    }
    int32_t LearnAutoIPara(AUTOPOOL *autoPool, float freq, AUTOIPARA *autoIPara)
    {
        println("LearnAutoIPara");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return LearnAutoIPara_(autoPool, freq, autoIPara);
        }
        else if (NULL != hmodule)
        {
            LearnAutoIPar_ fn = (LearnAutoIPar_)GetProcAddress(hmodule, "LearnAutoIPar_");
            if (NULL == fn)
            {
                fn = (LearnAutoIPar_)GetProcAddress(hmodule, "LearnAutoIPara");
            }
            if (NULL != fn)
            {
                return fn(autoPool, freq, autoIPara);
            }
        }
        return false;
#else
        return LearnAutoIPara_(autoPool, freq, autoIPara);
#endif
    }
    int32_t MakeAutoIPara(int32_t *buf, int32_t len, float freq, AUTOIPARA *autoIPara)
    {
        println("MakeAutoIPara");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return MakeAutoIPara_(buf, len, freq, autoIPara);
        }
        else if (NULL != hmodule)
        {
            MakeAutoIPar_ fn = (MakeAutoIPar_)GetProcAddress(hmodule, "MakeAutoIPar_");
            if (NULL == fn)
            {
                fn = (MakeAutoIPar_)GetProcAddress(hmodule, "MakeAutoIPara");
            }
            if (NULL != fn)
            {
                return fn(buf, len, freq, autoIPara);
            }
        }
        return false;
#else
        return MakeAutoIPara_(buf, len, freq, autoIPara);
#endif
    }
    int32_t MdyAnalStopTime(int32_t ch, float fMinutes)
    {
        println("MdyAnalStopTime");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return MdyAnalStopTime_(ch, fMinutes);
        }
        else if (NULL != hmodule)
        {
            MdyAnalStopTim_ fn = (MdyAnalStopTim_)GetProcAddress(hmodule, "MdyAnalStopTim_");
            if (NULL == fn)
            {
                fn = (MdyAnalStopTim_)GetProcAddress(hmodule, "MdyAnalStopTime");
            }
            if (NULL != fn)
            {
                return fn(ch, fMinutes);
            }
        }
        return false;
#else
        return MdyAnalStopTime_(ch, fMinutes);
#endif
    }
    int32_t MdyPeakSmpHead(int32_t ch, int32_t *pSmpHead)
    {
        println("MdyPeakSmpHead");
#ifdef _MSC_VER
        if (toggleVer)
        {
            return MdyPeakSmpHead_(ch, pSmpHead);
        }
        else if (NULL != hmodule)
        {
            MdyPeakSmpHea_ fn = (MdyPeakSmpHea_)GetProcAddress(hmodule, "MdyPeakSmpHea_");
            if (NULL == fn)
            {
                fn = (MdyPeakSmpHea_)GetProcAddress(hmodule, "MdyPeakSmpHead");
            }
            if (NULL != fn)
            {
                return fn(ch, pSmpHead);
            }
        }
        return false;
#else
        return MdyPeakSmpHead_(ch, pSmpHead);
#endif
    }

    CAnalysis::CAnalysis()
    {
        return;
    }

#ifndef _MSC_VER
    int32_t check()
    {
        printConstant();
        return true;
    }

    int32_t add(int32_t a, int32_t b)
    {
        return a + b;
    }
#endif
}